﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TA.JSON;

namespace TA.Turbo
{
	/// <summary>
	/// Contains the progress of a <see cref="FileUploadOperation"/>.
	/// </summary>
	public class FileUploadProgress : IJsonSerializable
	{
		#region PUBLIC
		#region INIT
		internal FileUploadProgress(long totalSize)
		{
			this._totalSize = totalSize;
			this._totalStartDT = DateTime.Now;
		}
		#endregion
		#region PROPS
		/// <summary>
		/// Gets the total size of all files.
		/// </summary>
		public long TotalSize { get { return this._totalSize; } }
		/// <summary>
		/// Gets the total uploaded bytes of all files.
		/// </summary>
		public long TotalUploaded { get { return this._totalUploaded; } }
		/// <summary>
		/// Gets the size of the currently uploaded file, if available.
		/// </summary>
		public long FileSize { get { return this._fileSize; } }
		/// <summary>
		/// Gets the uploaded bytes of the currently uploaded file, if available.
		/// </summary>
		public long FileUploaded { get { return this._fileUploaded; } }
		/// <summary>
		/// Gets the <see cref="DateTime"/> stamp when the whole upload started.
		/// </summary>
		public DateTime TotalStartDT { get { return this._totalStartDT; } }
		/// <summary>
		/// Gets the <see cref="DateTime"/> stamp when the current file upload started.
		/// </summary>
		public DateTime FileStartDT { get { return this._fileStartDT; } }
		/// <summary>
		/// Gets the name of the current file.
		/// </summary>
		public string FileName { get { return this._fileName; } }
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		DateTime _totalStartDT, _fileStartDT;
		long _totalSize;
		internal long _totalUploaded = 0,
			_fileSize = 0, 
			_fileUploaded = 0;
		string _fileName;
		#endregion
		#region METHODS
		internal void StartFile(string name, long size)
		{
			this._fileStartDT = DateTime.Now;
			this._fileName = name;
			this._fileSize = size;
		}
		#region JSON
		public bool IsDirty
		{
			get { return true; }
		}
		public void Serialize(JsonWriter jw)
		{
			this.SerializeObject(jw);
		}
		public void SerializeContents(JsonWriter jw)
		{
			jw.PropertyName("A");
			jw.Value(this.TotalSize);

			jw.PropertyName("B");
			jw.Value(this.TotalUploaded);

			jw.PropertyName("C");
			jw.Value(this.FileSize);

			jw.PropertyName("D");
			jw.Value(this.FileUploaded);

			jw.PropertyName("E");
			jw.Value(this.TotalStartDT);

			jw.PropertyName("F");
			jw.Value(this.FileStartDT);

			jw.PropertyName("N");
			jw.Value(this.FileName);
		}
		#endregion
		#endregion
		#endregion
	}
}
